<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>日志管理</title>
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath }/styles/admin/noteManage.css" />
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath }/styles/pagination.css" />
	</head>

	<body>
		<jsp:include page="include/header.jsp" />
		<!-- 导入无刷新分布插件-->
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.pagination.js">
		</script>
		<script type="text/javascript">
			//记住$.extend();的用法。json的覆盖 曾为这浪费了两个小时
			var url="admin/noteManageAction_getNoteManageList.action";
			var defaultParamater={"pageSize":2,"pageCurrent":0,"pageCount":0,"cid":-1};
			$("document").ready(function(){
				init();
				//时间排序 
				$("#atTime").click(function(){
					init();
				});
				//按类别排序
				$("#atCategory").change(function(){
					$.extend(defaultParamater,{"cid":$("#atCategory").val()});
					init();
				});
			});
			function init(){
				$.post("admin/noteManageAction_getNoteManagePageCount.action",{"pageSize":defaultParamater.pageSize,"cid":defaultParamater.cid},
							function(data){
								$.extend(defaultParamater,{"pageCount":data.pageCount});
								$("#Pagination").pagination(defaultParamater.pageCount * defaultParamater.pageSize, {
									num_edge_entries : 1, //边缘页数
									num_display_entries : 4, //主体页数
									callback : pageselectCallback,
									items_per_page : defaultParamater.pageSize
								});
							},"json"
					);
			}
			function pageselectCallback(page_index,jq){
				$.extend(defaultParamater,{"pageCurrent":page_index+1});
				$.post(url,defaultParamater,
					function(data){
						$("#tableMain tr").not(":first").remove();
						setData(data);
						$("#pageCount").html("当前："+(defaultParamater.pageCurrent)+"/" + defaultParamater.pageCount+"页　　每页显示"+defaultParamater.pageSize+"条");
					},"json");
					
			}
			function setData(data){
				var tt=$(data.List).each(function(i){
					var tr = $("#tableMain tr:first").clone();
	  				var temp = $(this);
	  				tr.find("td").eq(0).html( temp[0].aid  );
	  				tr.find("td").eq(1).html( temp[0].atitle );
	  				tr.find("td").eq(2).html( temp[1].cname );
	  				tr.find("td").eq(3).html( temp[0].atime );
	  				tr.find("td").eq(4).html( "<a href='javascript:;' class='checkO' lang='"+temp[0].aid+"'>查看评论</a>" );
	  				tr.find("td").eq(5).html( "<a href='javascript:;' class='update' lang='"+temp[0].aid+"'>更新</a>" );
	  				tr.find("td").eq(6).html( "<a href='javascript:;' class='delete' lang='"+temp[0].aid+"'>删除</a>"  );
	  				$("#tableMain").append(tr);
  				});
  				// 查看评论的操作
  				$(".checkO").click(function(){
					alert('this is test');
				});
				//修改
				$(".update").click(function(){
					//这里只需要跳转一个网址即可
					window.location="${pageContext.request.contextPath}/admin/noteManageAction_goUpdateNoteUi.action?article.aid="+$(this).attr("lang");
				});
				//删除
				$(".delete").click(function(){
					var choice=confirm("您确认要删除此日志吗？", function() { }, null);
						if(choice){
							$(this).parent().parent().remove();
							//发送ajax删除请求
							$.post("admin/noteManageAction_delNote.action",{"article.aid":$(this).attr("lang")},function(){},"json");
						}
				});
			}
		</script>
		<div id="right">
			<h1></h1>
			<div id="right_main">
				<div style="text-align:center;margin-bottom:10px;"><h2>日志管理</h2></div>
				<div id="addNote">
					<a href="${pageContext.request.contextPath }/admin/noteManageAction_addNoteUi.action">添加日志</a>
				</div>
				<div id="note_list">
					<table cellspacing="1" id="tableMain">
						<tr><td>日志ID</td><td>日志标题</td><td>类别名称</td><td>编写时间</td><td>评论查询</td><td>
								<a href="javascript:;" id="atTime">时间排序</a> 
							</td>
							<td>类别排序<br/><select name="cid" id="atCategory" >
														<option value="-1">请选择</option>
														<c:forEach items="${requestScope.categoryList}" var="category">
					            							<option value="${category.cid }">${category.cname }</option>
					            						</c:forEach>
													</select>
							</td>
						</tr>
					</table>
					<div id="Pagination" class="pagination"></div>
					<div id="pageCount"></div>
				</div>
			</div>
		</div>
		<jsp:include page="include/footer.jsp" />
	</body>
</html>
